﻿
using Edge.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace Edge.Utilities.Tests
{
    
    
    /// <summary>
    ///This is a test class for ByteArrayExtensionsTest and is intended
    ///to contain all ByteArrayExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ByteArrayExtensionsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Compress
        ///</summary>
        [TestMethod()]
        public void CompressDecompressTest()
        {
            string s;
            s = "A friend called me up the other day and talked about investing in a dot-com";
            s = s + " that sells lobsters. Internet lobsters. Where will this end? -- Donald Trump";
            s = s + s;
            s = s + s;
            byte[] uncompressed = s.ToByteArray();
            byte[] compressed = ByteArrayExtensions.Compress(uncompressed);
            bool expected = true;
            bool actual = compressed.Length < uncompressed.Length;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Trim
        ///</summary>
        [TestMethod()]
        public void TrimTest()
        {
            string s = "Hello, World!";
            byte[] bytes = s.ToByteArray();
            int length = 1;
            int expected = bytes.Length - 1;
            int actual;
            actual = ByteArrayExtensions.Trim(bytes, length).Length;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ByteArrayToString
        ///</summary>
        [TestMethod()]
        public void ByteArrayToStringTest()
        {
            string s = "Hello, World!";
            byte[] bytes = s.ToByteArray();
            string expected = s;
            string actual;
            actual = ByteArrayExtensions.ByteArrayToString(bytes);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for WriteToFile
        ///</summary>
        [TestMethod()]
        public void WriteToFileTest()
        {
            string s = "Hello, World!";
            byte[] bytes = s.ToByteArray();
            string fileName = Path.GetTempPath() + "temp.txt";
            int expected = bytes.Length;
            ByteArrayExtensions.ToFile(bytes, fileName, FileMode.Create);
            Assert.AreEqual(expected, (new FileInfo(fileName)).Length);
        }
    }
}
